/**
* @file
* @author renzhiqiang
* @date 2017-04-13
*/
<template>
  <div>
    <header id="header" class="mui-bar mui-bar-nav" style="position: fixed;">
      <h1 class="mui-title">{{language.SI}}</h1>
    </header>
    <div class="mui-content" style="padding-top: 100px;">
      <div v-show="login.show" style="text-align: center;padding: 18px;">
        <input type="text" v-model="login.loginData.phone" @input='change' placeholder={{language.PE}}><br>
        <input type="password" v-model="login.loginData.password" @input='change' placeholder={{language.PW}}>
      </div>
      <button type="button" id='button' disabled class="mui-btn mui-btn-SingIn" @tap="loginFn()">{{language.SI}}</button>
      <div class="contents mt23">
        <div class="left" @tap="registerFn">
          {{language.RN}}
        </div>
        <div class="right" @tap="forgetFn">
          {{language.FP}}
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import store from '../login-store';
  import {FastClick} from 'fastclick';
  import {tools} from 'tools';
  var lan = require('./../language.json');
  export default {
    components: {},
    data: function () {    // 组件的数据格式
      console.info(lan);
      return {
        login: store.state,
        language: lan[window.lan],
        r: tools.getQueryString('r')
      };
    },
    methods: {
      loginFn: function () {
        var self = this;
        store.login(this.r, value => {
          self.$router.go('/registerSuccues/login');
//          this.$router.go('/loginSucess?r=' + value);
        }, 'login');
      },
      registerFn: function () {
        this.$router.go('/register/add?r=' + this.r);
      },
      forgetFn: function () {
        this.$router.go('/forget?r=' + this.r);
      },
      change: function () {
        if (this.login.loginData.phone && this.login.loginData.password) {
          document.getElementById('button').removeAttribute('disabled');
        } else {
          document.getElementById('button').setAttribute('disabled', true);
        }
      }
    },
    //  created 钩子在实例创建后,在reday之前调用
    created: function () {
      if (document.querySelector('head title')) {
        document.querySelector('head title').textContent = this.language.SIWTA;
      }
    },
    route: {
      data: function (data) {
        var self = this;
        store.state.r = self.r = tools.getQueryString('r');
      }
    },
    ready: function () {
      mui('.mui-scroll-wrapper').scroll();
      FastClick.attach(document.body);
    }
  };
</script>
